package com.briup.smartcity_group1.service.impl;

import com.briup.smartcity_group1.bean.basic.BaseLog;
import com.briup.smartcity_group1.dao.basic.BaseLogMapper;
import com.briup.smartcity_group1.dao.ext.BaseLogExtMapper;
import com.briup.smartcity_group1.service.IBaseLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Set;

import com.briup.smartcity_group1.log.LogAspect;

/** 日志模块服务实现
 * @author congee(congee02 @ 163.com)
 * @date 1/4/2023 2:31 PM
 */
@Service
public class BaseLogServiceImpl implements IBaseLogService {

    @Autowired
    private BaseLogMapper mapper;

    @Autowired
    private BaseLogExtMapper extMapper;

    /**
     * 分页查询日志信息
     *
     * @param pageNum  页码
     * @param pageSize 单页记录数
     * @return 页面信息
     */
    @Override
    public PageInfo<BaseLog> findByPage(int pageNum, int pageSize) {
        return PageHelper.startPage(pageNum, pageSize, true).
                doSelectPageInfo(() -> extMapper.selectAll());
    }

    /**
     * 添加日志信息
     * 在用户调用 service 层 接口 时通过 aop 记录 {@link LogAspect}
     *
     * @param baseLog 要添加的日志信息
     */
    @Override
    public void addBaseLog(BaseLog baseLog) {
        mapper.insert(baseLog);
    }
}
